package Objects工具类;

import java.util.Objects;

public class Objects01 {
    public static void main(String[] args) {
        String s1 = "abc";
        String s2 = "aaa";
        String s3 = null;

        boolean b = s1.equals(s2);
        System.out.println(b);

        //当s3为null时，不能调用方法，会产出空指针异常 java.lang.NullPointerException
        // boolean b2=s3.equals(s1);
        //解决方法：调用Objects中的equals

        boolean b2 = Objects.equals(s1, s3);
        System.out.println(b2);


        //Objects.equals()源码如下
        //Objects.equals容忍空指针
        // public static boolean equals(Object a, Object b) {
        //      比较的是对象的地址
        //     return (a == b) || (a != null && a.equals(b));
        // }



    }
}
